/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


$(document).ready(function(){

    $(".btnPublicationdownload").click(function(e){
       $(location).attr("href","http://"+location.hostname+"/downloaddata/ZipData?search="+$(this).attr("id"));
    });
});

function setApprovalStatus($rid, $stid, tabId, uid)
{
    $url = "http://"+location.hostname+"/publication/setPublicationApprovalStatus?rid=" + $rid + "&status=" + $stid + "&tid=" + document.getElementById( tabId).value + "&id=" + uid;
    
    $.post($url, {}, function(data) {
        $('#tdResearchList').html( data);
        setActiveTab(document.getElementById('lnkPendingPublicationList'));
    });
}

function removeCollaborativeUser(cUserId, rid)
{
    var flg = confirm('Are you sure you want to remove this user from research?');

    if(flg)
    {
        var tblcollaborativeUser = "#tdCollaboratorList_" + rid;
        $url = "http://"+location.hostname+"/publication/removeCollaborativeUser?cuid=" + cUserId + "&rid=" + rid;

        $(tblcollaborativeUser).html('<img src="/images/loading/loading9.gif">');
        $.post($url, {}, function(data) {
            $(tblcollaborativeUser).html( data);
        });
    }
    return false;
}

function loadNewCollaborativeUserDialog(top, left, isModal, containerId, rid, hfRid)
{
    // Clicking the Cancel link doesnt clear the control value (input box on Add User dialog)
    // So before showing the dialog clearing the value
    $('#txtMailTo').val('');
    $('#trErrorMessage').html('');

    dwidth = 400;
    dheight = 160;
    top = (document.documentElement.clientHeight - dheight)/2;
    left = (document.documentElement.clientWidth - dwidth)/2;

    document.getElementById(hfRid).value = rid;
    return showAsDialog(dwidth, dheight, top, left, isModal, containerId);
}

function addCollaborativeUser(rid, uDetail, showListView)
{
    var tblcollaborativeUser = "#tdCollaboratorList_" + rid;
    $url = "http://"+location.hostname+"/publication/addCollaborativeUser?uDetail=" + uDetail + "&rid=" + rid;

    if(showListView)
        $url += "&formatByList=1";

    $(tblcollaborativeUser).html('<img src="/images/loading/loading9.gif"/>');
    
    $.post($url, {}, function(data) {
        if(data.length == 0 || data[0] == '0')
        {
            $('#trErrorMessage').html('<td colspan=\'2\' align=\'center\'><span class=\'redFont\'>User already collaborating</span></td>');
            $(tblcollaborativeUser).html( data.substring(1) );
        }
        else if(data[0] == '1')
        {
            $('#trErrorMessage').html('<td colspan=\'2\' align=\'center\'><span class=\'redFont\'>A collaboration request is already pending for this user</span></td>');
            $(tblcollaborativeUser).html( data.substring(1) );
        }
        else
        {
            $(tblcollaborativeUser).html( data);
            $('.window').hide();
        }

    });
}

function LoadUserList() {
    $.post("http://"+location.hostname+"/publication/collaborationUserAutocomplete", {}, function(data) {
        $( "#txtMailTo" ).autocomplete({
            source: data.split("###"),
            minChars: 0,
            max: 10,
            autoFill: true,
            mustMatch: false,
            matchContains: "word",
            scrollHeight: 220
        }
        );
    });
}

function loadResearchVisualization(researchid,titleDesc)
{

window.open("http://"+location.hostname+"/visualization/index?RID="+researchid+"&ResearchTitle="+titleDesc,"_blank","toolbar=no,menubar=0,status=0,copyhistory=0,scrollbars=no,resizable=1,location=0");
}